<?php
function pages($page_number,$num_pages,$max_pages,$path,$extra='',$class='pagination') {
if($page_number==0) {

$page_number=1;	
}
$_pn=$page_number;

	if($page_number <=1) {
	// there is no previous
		$previous='';
	} else { 
		
		$paff=str_replace("page=".$_pn,"page=".($page_number-1),$path);
		
		$previous='<a rel="'.($page_number-1).'" href="'.$paff.$extra.'" class="'.$class.' tip" title="Goto Previous Page">Prev</a>'; 
	}
	
	if( ($page_number >= $num_pages) && ($page_number >= $max_pages) ) {
		$next="";
	} else {
				$paff=str_replace("page=".$_pn,"page=".($page_number+1),$path);

		$next='<a rel="'.($page_number+1).'" href="'.$paff.$extra.'" class="'.$class.' tip" title="Goto Next Nage">Next</a>';
	}

$pn=$page_number;
// change page number to accomidate
	// could go left and right of it dividing the max pages by 2
	// left side



	if( ($page_number-($max_pages/2)) <=1  ) {
	//for loop it
		//echo("<h1> : ".($page_number-($max_pages/2))."</h1>");

	
	for($m=1;$m<$page_number;$m++)
		{
					$paff=str_replace("page=".$_pn,"page=".($m),$path);

			$left.='<a rel="'.$m.'" class="'.$class.' tip" href="'.$paff.$extra.'" title="Goto Page '.$m.'">'.$m.'</a>';
		}
	unset($m);
	} else {
	
	for($m=$page_number-ceil(($max_pages/2));$m<$page_number;$m++)
		{
			//	echo("WTF");
			$paff=str_replace("page=".$_pn,"page=".($m),$path);
			$left.='<a rel="'.$m.'" class="'.$class.' tip" href="'.$paff.$extra.'" title="Goto Page '.$m.'">'.$m.'</a>';
		//	$left.='<a rel=\"$m\" href='$path/page/$m/$extra' title='Goto Page ".$m."'>".$m."</a> </li>";
		}
	
	
	}
	
	
	// check the page is out of view
	if( ($page_number > 1) && ($page_number-($max_pages/2) >= 1)) {
	
		if(($page_number-($max_pages/2) >= 1)) {
		
	//	$concatLeft="<li class=\"pagedli\"><a rel=\"".($page_number-($max_pages/2))."\" href='$path/page/".($page_number-($max_pages/2))."/$extra' title='Goto Back'>....</a></li>";
	} else { 		//$concatLeft="<li class=\"pagedli\">...</li>"; 
	}
	}
	if( (($page_number + $max_pages) < $num_pages)) {
	
	//	$concatRight="<li class=\"pagedli\">...</li>";
	
	}
	if(($page_number > 1)) {
		$paff=str_replace("page=".$_pn,"page=1",$path);
		$first='<a rel="1" href="'.$paff.$extra.'" title="Goto First Page" class="'.$class.' tip">&laquo;&laquo;</a>';
	}
	if(($page_number!=$num_pages)) {
		
		$paff=str_replace("page=".$_pn,"page=".($num_pages),$path);
		$last='<a rel="'.$num_pages.'" class="'.$class.' tip" href="'.$paff.$extra.'" title="Goto Last Page">&raquo;&raquo;</a>';
	}
	// now go right of it
	// gone right // only goes 5 for some reason ... put in a check for that
	for($i=$page_number;$i<=$num_pages;$i++) {
		if( $x<($max_pages)) {
			if($page_number==0) { $page_number=1; }
			if($i!=$page_number) {
				
				if($i==0) {
				$right.="";
				} else {
				$paff=str_replace("page=".$_pn,"page=".($i),$path);
				$right.='<a rel="'.$i.'" class="'.$class.' tip" href="'.$paff.$extra.'" title="Goto Page '.$i.'">'.$i.'</a>';
				}
			} else {
				
				//
				$paff=str_replace("page=".$_pn,"page=".($i),$path);
				$right.='<a href="'.$paff.$extra.'" class="'.$class.' '.$class.'-selected" rel="'.$i.'">'.$i.'</a>';

			}
		}
			$x++;

	}
	if($page_number==$num_pages) {
	$next="";
	}
	
if($num_pages>1) {
return $pageOutput.$first.$previous.$concatLeft.$left.$right.$concatRight.$next.$last;
	} else {
		return "";
	}
}
?>